package com.cn.wanxi.dao.impl;

import com.cn.wanxi.dao.CookTypeDao;
import com.cn.wanxi.model.CookTypeModel;
import com.cn.wanxi.util.JDBC;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class CookTypeImpl implements CookTypeDao {
    @Override
    public List<CookTypeModel> findAll() {
        String sql = "select * from cuisine";
        ResultSet resultSet = JDBC.find(sql);
        List<CookTypeModel> list = new ArrayList<>();
        try {
            while (resultSet.next()) {
                CookTypeModel cookTypeModel = new CookTypeModel();
                cookTypeModel.setName(resultSet.getString("name"));
                cookTypeModel.setId(resultSet.getInt("id"));
                list.add(cookTypeModel);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return list;
    }
}
